home *** CD-ROM | disk | FTP | other *** search
- /*
- C driver.c
- link driver.c.o -o driver -t MPST -c 'MPS ' ∂
- "{clibraries}"cruntime.o "{clibraries}"stdclib.o ∂
- "{clibraries}"cinterface.o "{libraries}"interface.o
-
- */
-
- #include <types.h>
- #include <string.h>
- #include <stdio.h>
-
- #define MAXFILENAME 255
- #define MAXOPTIONS 1023
-
- int run_cpp = 1;
- int run_cc1 = 1;
- int run_asm = 1;
- int optimize = 1;
- int quiet_flag = 1;
- int echo_cmds = 0;
-
- int got_mc68020 = 0;
-
- char* output_filename;
- char* input_filename;
- char* toolplace;
- char* tmp;
-
- char cpp_options[MAXOPTIONS];
- char cc1_options[MAXOPTIONS];
- char asm_options[MAXOPTIONS];
-
- char tmp_filename[MAXFILENAME];
- char cpp_filename[MAXFILENAME];
- char asm_filename[MAXFILENAME];
- char out_filename[MAXFILENAME];
-
- main (argc, argv)
- int argc;
- char* argv[];
- {
- int i, badopt;
- char* arg;
- char* missing;
- char* basename;
-
- output_filename = "";
- input_filename = "";
- toolplace = "";
- tmp = ":";
-
- strcpy(cpp_options, "-D__GNUC__");
- cc1_options[0] = '\0';
- strcpy(asm_options, "-w");
-
- for (i=1; i<argc; i++)
- {
- arg = argv[i];
- badopt = 0;
- missing = "";
-
- if (arg[0] == '-') {
- switch(arg[1]) {
-
- case 'a':
- if (strcmp(arg, "-ansi") == 0)
- strcat(cc1_options, " -ansi");
- else if (strcmp(arg, " -asm") == 0)
- run_asm = 0;
- else
- badopt = 1;
- break;
-
- case 'b':
- if (arg[2] == '\0')
- strcat(cc1_options, " -mb");
- else if ( (arg[2] == '2' || arg[2] == '3') && arg[3] == '\0' )
- fprintf(stderr, "Warning: %s ignored\n", arg);
- else
- badopt = 1;
- break;
-
- case 'c':
- if (arg[2] == '\0')
- run_cc1 = 0;
- else
- badopt = 1;
- break;
-
- case 'd':
- if (arg[2] == '\0') {
- if (++i<argc) {
- strcat(cpp_options, " -D");
- strcat(cpp_options, argv[i]);
- }
- else
- missing = "symbol";
- }
- else {
- strcat(cc1_options, " ");
- strcat(cc1_options, arg);
- }
- break;
-
- case 'e':
- if (arg[2] == '\0') {
- strcat(cpp_options, " -C");
- run_cc1 = 0;
- }
- else if (arg[2] == '2' && arg[3] == '\0')
- run_cc1 = 0;
- else if (strcmp(arg, "-elems881") == 0)
- strcat(cc1_options, " -melems881");
- else
- badopt = 1;
- break;
-
- case 'f':
- if (arg[2] == 'x' && arg[3] == '\0') {
- if (++i>=argc)
- missing = "number";
- else if (strcmp(argv[i], "30") == 0)
- strcat(cc1_options, " -mfx30");
- else
- fprintf(stderr, "Warning: -fx %s ignored.\n", argv[i]);
- }
- else {
- strcat(cc1_options, " ");
- strcat(cc1_options, arg);
- }
- break;
-
- case 'i':
- if (arg[2] == '\0') {
- if (++i<argc) {
- strcat(cpp_options, " '-I");
- strcat(cpp_options, argv[i]);
- strcat(cpp_options, "'");
- }
- else
- missing = "directory";
- }
- else
- badopt = 1;
- break;
-
- case 'm':
- if (arg[2] == '\0') {
- strcat(cc1_options, " -mm");
- if (got_mc68020 == 0) {
- fprintf(stderr, "Warning: -m implies -mc68020\n");
- strcat(cpp_options, " -Dmc68020");
- strcat(cc1_options, " -mc68020");
- got_mc68020 = 1;
- }
- }
- else if (strcmp(arg, "-makedep") == 0) {
- strcat(cpp_options, " -M");
- run_cc1 = 0;
- }
- else if (strcmp(arg, "-mbg") == 0) {
- if (++i<argc) {
- if (strcmp(argv[i], "off") == 0)
- strcat(cc1_options, " -mbgoff -fomit-frame-pointer");
- else if (strcmp(argv[i], "full") != 0)
- fprintf(stderr, "Warning: only -mbg off and -mbg full are supported.\n");
- }
- else
- missing = "\"full\" or \"off\"";
- }
- else if (strcmp(arg, "-mc68020") == 0) {
- if (got_mc68020 == 0) {
- strcat(cpp_options, " -Dmc68020");
- strcat(cc1_options, " -mc68020");
- got_mc68020 = 1;
- }
- }
- else if (strcmp(arg, "-mc68881") == 0) {
- strcat(cpp_options, " -Dmc68881");
- strcat(cc1_options, " -mc68881");
- }
- else if (strcmp(arg, "-mnoseg") == 0)
- strcat(cc1_options, " -mnoseg");
- else
- badopt = 1;
- break;
-
- case 'n':
- if (strcmp(arg, "-no") == 0)
- optimize = 0;
- else if (arg[2] == '\0')
- fprintf(stderr, "Warning: -n ignored.\n");
- else
- badopt = 1;
- break;
-
- case 'o':
- if (arg[2] == '\0') {
- if (++i<argc)
- output_filename = argv[i];
- else
- missing = "output filename";
- }
- else
- badopt = 1;
- break;
-
- case 'p':
- if (arg[2] == '\0') {
- strcat(cpp_options, " -v");
- strcat(cc1_options, " -version");
- quiet_flag = 0;
- strcat(asm_options, " -p");
- echo_cmds = 1;
- }
- else if (strcmp(arg, "-pedantic") == 0) {
- strcat(cpp_options, " -pedantic");
- strcat(cc1_options, " -pedantic");
- }
- else
- badopt = 1;
- break;
-
- case 'r':
- if (arg[2] == '\0')
- strcat(cc1_options, " -Wimplicit");
- else
- badopt = 1;
- break;
-
- case 's':
- if (arg[2] == '\0') {
- if (++i<argc) {
- strcat(cc1_options, " -s '");
- strcat(cc1_options, argv[i]);
- strcat(cc1_options, "'");
- }
- else
- missing = "segment name";
- }
- else if (strcmp(arg, "-sym") == 0)
- if (++i<argc) {
- strcat(asm_options, " -sym ");
- strcat(asm_options, argv[i]);
- fprintf(stderr, "Warning: symbolic info will be produced by assembler.\n");
- }
- else
- missing = "option";
- else
- badopt = 1;
- break;
-
- case 't':
- if (arg[2] == '\0') {
- quiet_flag = 0;
- strcat(asm_options, " -t");
- }
- else if (strcmp(arg, "-tools") == 0) {
- if (++i<argc)
- toolplace = argv[i];
- else
- missing = "directory";
- }
- else if (strcmp(arg, "-traditional") == 0) {
- strcat(cpp_options, " -traditional");
- strcat(cc1_options, " -traditional");
- }
- else
- badopt = 1;
- break;
-
- case 'u':
- if (arg[2] == '\0') {
- if (++i<argc) {
- strcat(cpp_options, " -U");
- strcat(cpp_options, argv[i]);
- }
- else
- missing = "symbol";
- }
- else
- badopt = 1;
- break;
-
- case 'w':
- if (arg[2] == '\0')
- strcat(cc1_options, " -w");
- else if (arg[2] == '2' && arg[3] == '\0')
- strcat(cc1_options, " -Wall");
- else {
- strcat(cc1_options, " ");
- strcat(cc1_options, arg);
- }
- break;
-
- case 'y':
- if (arg[2] == '\0') {
- if (++i<argc)
- tmp = arg;
- else
- missing = "directory";
- }
- else
- badopt = 1;
- break;
-
- default:
- badopt = 1;
- }
-
- if (missing[0] != '\0')
- fprintf(stderr, "Warning: missing %s after \"%s\".\n", missing, arg);
- else if (badopt)
- fprintf(stderr, "Warning: invalid option %s ignored.\n", arg);
- }
-
- else if (input_filename[0] == '\0')
- input_filename = arg;
-
- else
- fprintf(stderr, "Warning input filename %s ignored.\n", arg);
- }
-
- if (input_filename[0] == '\0') {
- fprintf(stderr, "Error: no input filename.\n");
- exit(2);
- }
-
- strcpy(tmp_filename, tmp);
- if ( (basename = strrchr(input_filename, ':')) != NULL)
- strcat(tmp_filename, basename);
- else
- strcat(tmp_filename, input_filename);
-
- if (run_cc1 == 1) {
- strcpy(cpp_filename, tmp_filename);
- strcat(cpp_filename, ".cpp");
- }
-
- strcpy(asm_filename, tmp_filename);
- strcat(asm_filename, ".a");
-
- if (output_filename[0] == '\0') {
- strcpy(out_filename, input_filename);
- strcat(out_filename, ".o");
- output_filename = out_filename;
- }
-
- if (quiet_flag == 1)
- strcat(cc1_options, " -quiet");
-
- if (optimize == 1)
- strcat(cc1_options, " -O");
-
- printf("set oldexit {exit}\n");
- printf("set exit 0\n");
-
- if (echo_cmds == 1) {
- printf("set oldecho {echo}\n");
- printf("set echo 1\n");
- }
-
- if (run_cpp == 1) {
- printf("'%s'cpp %s %s %s\n", toolplace, cpp_options, input_filename, cpp_filename);
- printf("if {status} == 0\n");
-
- if (run_cc1 == 1) {
- printf("\t'%s'cc1 %s %s -o %s -dumpbase %s\n",
- toolplace, cc1_options, cpp_filename, asm_filename, tmp_filename);
- printf("\tif {status} == 0\n");
- printf("\t\tdelete -i -y %s\n", cpp_filename);
-
- if (run_asm == 1) {
- printf("\t\tasm %s %s -o %s\n", asm_options, asm_filename, output_filename);
- printf("\t\tif {status} == 0\n");
- printf("\t\t\tdelete -i -y %s\n", asm_filename);
- printf("\t\telse\n");
- printf("\t\t\tset exit {oldexit}\n");
- printf("\t\t\texit 2\n");
- printf("\t\tend\n");
- }
-
- printf("\telse\n");
- printf("\t\tdelete -i -y %s\n", cpp_filename);
- printf("\t\tdelete -i -y %s\n", asm_filename);
- printf("\t\tset exit {oldexit}\n");
- printf("\t\texit 2\n");
- printf("\tend\n");
-
- }
- printf("else\n");
- printf("\tdelete -i -y %s\n", cpp_filename);
- printf("\tset exit {oldexit}\n");
- printf("\texit 2\n");
- printf("end\n");
- }
-
- if (echo_cmds == 1)
- printf("set echo {oldecho}\n");
- printf("set exit {oldexit}\n");
-
- exit(0);
- }
-